package com.sudoku.command;

import java.util.ArrayList;

import com.sudoku.board.Tile;
import com.sudoku.mode.Mode;
import com.sudoku.utility.Constants;

public class EraseCommand extends Command implements Constants {

	private Tile tile;
	private char prevData;
	private ArrayList<Integer> prevPencil;
	private Mode mode;

	public EraseCommand(Mode mode, Tile t) {
		tile = t;
		this.mode = mode;
		prevData = tile.getData();
		prevPencil = new ArrayList<Integer>();
		prevPencil.addAll(tile.getPencilNumbers());
	}

	@Override
	public void execute() {
		tile.clearPencilNumbers();
		tile.setData(' ');
		mode.unhighlightTiles();
		mode.setSelectedTile(tile);
	}

	@Override
	public void undo() {
		tile.setPencilNumbers(prevPencil);
		tile.setData(prevData);
		mode.unhighlightTiles();
		mode.setSelectedTile(tile);
	}

}
